﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace XmlSpecParser
{
	public static class Program
	{
		private const string OutputPath = @"..\..\..\GLDotNet\";

		public static void Main(string[] args)
		{
			XmlSpecParser xmlParser = new XmlSpecParser();
			DotNetTranslator translator = new DotNetTranslator();
			DotNetFileWriter writer = new DotNetFileWriter();

            var glSpec = xmlParser.Parse(@"specs\gl.xml", @"specs\gl.overrides.xml", new XmlSpecParser.Options()
                {
                    Prefix = "gl",
                });
			XmlSerializer.WriteToFile(glSpec, "glSpecData.xml");

            var glCommands = glSpec.Features.Where(x => x.Api == "gl" && x.VersionMajor <= 3).SelectMany(x => x.Commands);

			var glApi = translator.Translate(glSpec, new DotNetTranslator.Options()
			    {
				    Prefix = "gl",
				    CommandFilter = x => glCommands.Contains(x.Name)
			    });
            XmlSerializer.WriteToFile(glApi, "glDotNetData.xml");

			writer.WriteFiles(glApi, new DotNetFileWriter.Options()
			    {
				    Prefix = "GL",
				    OutputPath = OutputPath,
				    StaticFileName = "GL.Generated.cs",
                    StaticClassName = "GL",
                    EnumsFileName = "GLEnums.Generated.cs",
				    NativeFunctionsFileName = "GLNative.Generated.cs",
				    NativeFunctionsClassName = "GLNative",
                    NativeFunctionsEnumFileName = "GLNativeFunctions.Generated.cs",
                    NativeFunctionsEnumClassName = "GLNativeFunctions",
				    DotNetFunctionsFileName = "GLContext.Generated.cs",
				    DotNetClassName = "GLContext"
			    });
		}
	}
}
